package com.qf.contorller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.service.OwnerService;
import com.qf.utils.R;
import com.qf.vo.OwnerVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zdl
 * @date 2025/2/15
 */
@RestController
@RequestMapping("/owner")
public class OwnerController {
    @Resource
    private OwnerService ownerService;

    @GetMapping("/all")
    public R<PageInfo<OwnerVo>> findAllOwnerWithRoomWithBuildingByBuildingNameOrOwenerNam(String buildingName, String ownerName, @RequestParam int pageNum, @RequestParam int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<OwnerVo> allOwnerWithRoomWithBuildingByBuildingNameOrOwenerName = ownerService.findAllOwnerWithRoomWithBuildingByBuildingNameOrOwenerName(buildingName, ownerName);
        PageInfo<OwnerVo> ownerVoPageInfo = new PageInfo<>(allOwnerWithRoomWithBuildingByBuildingNameOrOwenerName);
        return R.ok(ownerVoPageInfo);
    }

    @GetMapping("/{oid}")
    public R<Integer> delOwnerByOid(@PathVariable("oid") int oid){
        return R.ok(ownerService.delOwnerByOid(oid));
    }
}
